# $Id: PKGBUILD 77568 2012-10-12 15:43:08Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Stefan Bergstrom <stefan.bergstrom@gmail.com>

pkgname=gnump3d
pkgver=3.0
pkgrel=7
url="http://www.gnu.org/software/gnump3d/"
arch=(any)
pkgdesc="A streaming server for MP3s, OGG vorbis files, movies and other media formats."
license=("GPL")
depends=('sh' 'perl')
backup=('etc/gnump3d/gnump3d.conf')
install=gnump3d.install
source=("http://savannah.gnu.org/download/$pkgname/$pkgname-$pkgver.tar.bz2"
	'gnump3d'
	'gnump3d.service'
	'gnump3d-proxy.patch')
md5sums=('41786650bbc591484c08014a89478bf9'
         '4ac4fd5f3637613a5b5a191081437e23'
         'a9b8a415da859775ce30f1c1ff659739'
         '9978f8a8c10a87496e8920a09fb5e9e6')

build() {
    cd $srcdir/$pkgname-$pkgver

    patch -p1 <$srcdir/gnump3d-proxy.patch

    install -d $pkgdir/var/log/gnump3d
    install -d $pkgdir/var/cache/gnump3d/serving

    install -d $pkgdir/usr/share/perl5/vendor_perl/gnump3d/plugins
    install -d $pkgdir/usr/share/perl5/vendor_perl/gnump3d/lang
    install -m 644 lib/gnump3d/*.pm         $pkgdir/usr/share/perl5/vendor_perl/gnump3d
    install -m 644 lib/gnump3d/plugins/*.pm $pkgdir/usr/share/perl5/vendor_perl/gnump3d/plugins
    install -m 644 lib/gnump3d/lang/*.pm    $pkgdir/usr/share/perl5/vendor_perl/gnump3d/lang

    install -d $pkgdir/usr/bin
    install -m 755 bin/gnump3d2 $pkgdir/usr/bin/gnump3d
    install -m 755 bin/gnump3d-top bin/gnump3d-index $pkgdir/usr/bin

    install -d $pkgdir/usr/share/man/man1
    install -m 644 man/gnump3d-top.1 man/gnump3d-index.1 man/gnump3d.1 man/gnump3d.conf.1 $pkgdir/usr/share/man/man1

    install -d $pkgdir/usr/share/gnump3d
    cp -R templates/* $pkgdir/usr/share/gnump3d
    chmod -R a+r $pkgdir/usr/share/gnump3d
    chmod +rx $pkgdir/usr/share/gnump3d/*/

    sed -i "s|PLUGINDIR|/usr/share/perl5/vendor_perl|g" etc/gnump3d.conf
    install -d $pkgdir/etc/gnump3d
    install -m 644 etc/gnump3d.conf etc/mime.types $pkgdir/etc/gnump3d
    install -m 644 etc/gnump3d.conf etc/file.types $pkgdir/etc/gnump3d

    mkdir -p $pkgdir/srv/mp3
    sed -i "s|/home/mp3|/srv/mp3|" $pkgdir/etc/gnump3d/gnump3d.conf

    install -D -m 755 $srcdir/gnump3d $pkgdir/etc/rc.d/gnump3d
    install -Dm0644 $srcdir/$pkgname.service $pkgdir/usr/lib/systemd/system/$pkgname.service
}
